package com.webster.isw.core.service;

import org.quartz.*;

import java.util.*;

/**
 * 计划任务服务
 * TODO 计划和ScheduledJobService重构
 * Created by Webster on 16/5/8.
 */
public interface ScheduledService extends BaseService {


    /**
     * Description: 获得作业的dataMap
     */
    Map<String, Object> getJobData(String jobName, String jobGroup) throws SchedulerException;

    /**
     * Description: 返回执行历史清单
     */
    Map<String, Object> getExecutedJob(int pageNum, int pageSize,
                                       String triggerGroup, String triggerName,
                                       String jobGroup, String jobName,
                                       String status) throws Exception;

    /**
     * Description: 返回操作历史清单
     */
    Map<String, Object> getSchedulerLog(int pageNum, int pageSize) throws Exception;

    /**
     * Description: 计划任务操作
     */
    Map<String, Object> getSchedulerOperate(String operate, String jobName, String jobGroup,
                                            String triggerName, String triggerGroup) throws Exception;

    /**
     * Description: 清除计划任务数据
     */
    Map<String, Object> clearnScheduler(String password) throws SchedulerException;

    /**
     * Description: 返回触发器组别列表
     */
    List<Map<String, Object>> getTriggerGroup() throws SchedulerException;

    /**
     * Description: 返回作业组别列表
     */
    List<Map<String, Object>> getJobGroup() throws SchedulerException;

    /**
     * Description: 启动任务
     */
    Map<String, Object> startScheduler(int waitSeconds) throws SchedulerException;

    /**
     * Description: 获得jobDataMap
     */
    JobDataMap getJobDataMap(String jsonJobData);

    /**
     * Description: 添加作业
     */
    @SuppressWarnings("unchecked")
    Map<String, Object> addJob(String jobName, String jobGroup, String jobClass, String jobDesc,
                               boolean jobShouldRecover, boolean jobDurability, String jsonJobData) throws Exception;

    /**
     * Description: 添加cron触发器
     */
    Map<String, Object> addCronTrigger(String jobName, String jobGroup, String triggerName, String triggerGroup,
                                       String cronExpression, int priority, Date triggerStartAt, Date triggerEndAt) throws Exception;

    /**
     * Description: 添加简单触发器
     */
    Map<String, Object> addSimpleTirgger(String jobName, String jobGroup, String triggerName, String triggerGroup,
                                         int triggerRepeatCount, long intervalSeconds, int priority, Date triggerStartAt,
                                         Date triggerEndAt) throws Exception;

    /**
     * Description: 计划任务待机
     */
    Map<String, Object> standbyScheduler() throws SchedulerException;

    /**
     * Description: 停止计划任务
     */
    Map<String, Object> shutDownScheduler(boolean isWaitJobsComplete) throws SchedulerException;

    /**
     * Description: 返回计划任务当前状态
     */
    Map<String, Object> getSchedulerStatus() throws SchedulerException;

    /**
     * Description: 返回触发器类型
     */
    String getTriggerType(String scheduledName, String triggerName, String triggerGroup);

    /**
     * Description: 返回作业列表
     */
    List<Map<String, Object>> getJobList();

    /**
     * Description: 返回作业明细
     */
    Map<String, Object> getJob(String scheduledName, String jobName, String jobGroup);

    /**
     * Description: 返回Cron触发器明细
     */
    Map<String, Object> getCronTrigger(String scheduledName, String triggerName, String triggerGroup);

    /**
     * Description: 返回cron触发器列表
     */
    List<Map<String, Object>> getCronTriggerList(String scheduledName, String jobName, String jobGroup);

    /**
     * Description: 根据作业返回简单触发器清单
     */
    List<Map<String, Object>> getSimpleTriggerList(String scheduledName, String jobName, String jobGroup);

    /**
     * Description: 返回简单触发器明细
     */
    Map<String, Object> getSimpleTrigger(String scheduledName, String triggerName, String triggerGroup);

    /**
     * Description: 返回计划任务状态列表
     */
    List<Map<String, Object>> getScheduledState();

    /**
     * Description: 获取当前正在执行的任务列表
     */
    List<Map<String, Object>> getFiredTriggers();

    /**
     * Description: 获取计划任务列表
     */
    List<Map<String, Object>> getIntentTriggers(String triggerName, String triggerGroup, String jobName,
                                                String jobGroup, String sequence, String orderBy);

    /**
     * Description: 返回MetaData
     */
    Map<String, Object> getScheduledMetaData() throws SchedulerException;
}